package com.wander.concurrent;

import java.util.concurrent.TimeUnit;

public class WaitExample {
    public static void main(String[] args) throws InterruptedException {
        Object lock = new Object();

        Thread thread = new Thread(() -> {
            synchronized (lock) {
                try {
                    System.out.println("Waiting for lock");
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        thread.start();
        TimeUnit.SECONDS.sleep(1);
        synchronized (lock) {
            System.out.println("Waiting for notify");
            lock.notify();
        }
        System.out.println("exit....");
    }
}
